<template xmlns="http://www.w3.org/1999/html">
  <div class="app-container">
    <!-- 查询条件区域-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-="82px">
      <el-form-item label="巡检点位" prop="point">
        <el-input
          v-model="queryParams.point"
          placeholder="请输入巡检点位"
          clearable
          @keyup.enter.native="handleQuery"
          size="small"
        />
      </el-form-item>
      <el-form-item label="视频名称" prop="video_name">
        <el-input
          v-model="queryParams.video_name"
          placeholder="请输入视频名称"
          clearable
          @keyup.enter.native="handleQuery"
          size="small"
        />
      </el-form-item>
      <el-form-item label="分析结果" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选分析结果">
          <el-option
            v-for="dict in dict.type.sys_aeration_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--增删改查按钮区域-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['robot:aerationresult:remove']"
        >删除</el-button>
      </el-col>
    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
<!--  数据列表区域-->
    <el-table v-loading="loading" :data="areationresultList" @selection-change="handleSelectionChange" :cell-style="{borderColor:'rgb(1 5 43)'}" :header-cell-style="{borderColor: 'rgb(1 5 43)'}" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="巡检点" align="center" prop="point">
        <template slot-scope="scope">
          <span>{{scope.row.point}}#点位</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="frameindex">
        <template slot-scope="scope">
          <span v-if="scope.row.alarmtype == -1">正常</span>
          <span v-else-if="scope.row.alarmtype == 0">小气泡</span>
          <span v-else-if="scope.row.alarmtype == 1">泡沫</span>
          <span v-else-if="scope.row.alarmtype == 2">大泡沫堆积</span>
          <span v-else-if="scope.row.alarmtype == 3">小块污泥</span>
          <span v-else-if="scope.row.alarmtype == 4">大块污泥堆积</span>
          <span v-else-if="scope.row.alarmtype == 5">液面</span>
          <span v-else>其他</span>
        </template>
      </el-table-column>
      <el-table-column label="视频类型" align="center" prop="video_path">
        <template slot-scope="scope">
          <span v-if="scope.row.video_path=='qsp'" style="color: #495aef!important;">前摄像</span>
          <span v-else style="color: #4f8dd9!important;">后摄像</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="视频名称" align="center" prop="video_name" width="290"/>-->
      <!--      <el-table-column label="视频地址" align="center" prop="video_path" width="180"/>-->
<!--      <el-table-column label="曝气值" align="center" prop="aeration_value" width="130" />-->
      <el-table-column label="分析结果" align="center" prop="state">
        <template slot-scope="scope">
          <span v-if="scope.row.state==0" style="color: #158817!important;">正常</span>
          <span v-else-if="scope.row.state==1" style="color: #932d08!important;">报警</span>
        </template>
      </el-table-column>
      <el-table-column label="报警值" align="center" prop="alarm"/>
      <el-table-column label="视频采集时间" align="center" prop="video_time">
        <template slot-scope="scope">
          <span>{{parseTime(scope.row.video_time) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结果分析时间" align="center" prop="create_time">
        <template slot-scope="scope">
          <span>{{parseTime(scope.row.create_time) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['robot:aerationresult:add']"
          >原视频</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView1(scope.row)"
              v-hasPermi="['robot:aerationresult:add']"
          >结果视频</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['robot:aerationresult:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<!--列表分页区域-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" style="background:rgb(1 5 43);"
    />
<!--视频回放对话框-->
    <el-dialog :title="title" :visible.sync="open" width="650px">
      <videoPlayer
        class="vjs-custom-skin videoPlayer"
        ref="videoplayer"
        :playsinline="true"
        width="800px"
        height="600px"
        :options="playerOptions"
        customEventName="changed"
      >
      </videoPlayer>
      <div slot="footer" class="dialog-footer">
          <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import "@/assets/styles/robt-bg.css";
import {
  delAerationResult,
  getResultVideo,
  getUploadVideo,
  listAerationResult
} from "@/api/robot/aerationresult/aerationresult";
import {videoPlayer} from "vue-video-player";
import 'video.js/dist/video-js.css';
import 'vue-video-player/src/custom-theme.css';
import 'videojs-contrib-hls';
export default {
  dicts: ['sys_aeration_state'],
  components: {
    videoPlayer,
  },
  data() {
    return {
      sys_aeration_state:"",
      playerOptions: {
        width: "610px",
        height: "400px",
        language: "zh-CN",
        playbackRates: [0.7, 1.0, 1.5, 2.0], // 播放速度
        muted: false,// 默认情况下将会消除任何音频
        autoplay: false,// 如果true,浏览器准备好时开始回放。
        controls: true, //不显示暂停、声音、进度条组件
        loop: false, // 视频一结束就重新开始。
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        notSupportedMessage: "此视频暂无法播放，请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        sources: [
          {
            type: "video/mp4",
            src: "", // url地址
          },
        ],
        controlBar: {
          timeDivider: false, // 当前时间和持续时间的分隔符
          durationDisplay: true, // 显示持续时间
          remainingTimeDisplay: true, // 是否显示剩余时间功能
          fullscreenToggle: true, // 是否显示全屏按钮
        }
      },
      //遮罩层
      loading: true,
      //选中数组
      ids: [],
      //非单个禁用
      single: true,
      //非多个禁用
      multiple: true,
      //显示搜索条件
      showSearch: true,
      //总条数
      total: 0,
      areationresultList: [],
      //弹出层标题
      title: "",
      //是否显示弹出层
      open: false,
      //查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        video_name:undefined,
        point:undefined,
        create_time:undefined
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /*原视频回放*/
    handleView(row){
      let mediaUrl = row.video_name;
      this.getMedia(mediaUrl);
    },//结果视频回放
    handleView1(row) {
      let mediaUrl = row.video_name;
      this.getMedia1(mediaUrl);
    },
    //获取视频，并播放视频
    getMedia(mediaUrl) {
      getUploadVideo(mediaUrl).then(response => {
        if(typeof response.data !="undefined"){
          let videopath = response.data.videopath;
          console.log("原视频地址："+videopath)
          if(videopath!=""){
            this.open = true;
            this.title = "查看原视频";
            this.playerOptions.sources[0].src = videopath;
          }else{
            this.$modal.msgError("未查到原视频！");
          }
        }else {
          this.$modal.msgError("未查到原视频！");
        }
      });
    }, //获取结果视频，并播放视频
    getMedia1(mediaUrl) {
      getResultVideo(mediaUrl).then(response => {
        if(typeof response.data !="undefined"){
          let videopath = response.data.videopath;
          console.log("结果视频地址："+videopath)
          if(videopath!=""){
            this.open = true;
            this.title = "查看结果分析视频";
            this.playerOptions.sources[0].src = videopath;
          }else{
            this.$modal.msgError("未查到结果视频！");
          }
        }else {
          this.$modal.msgError("未查到结果视频！");
        }
      });
    },
    //预览功能
    preview() {
      console.log("preview");
    },
    //停止全部预览功能
    stopAllPreview() {},
    //关闭视频窗口
    closeWindow() {},
    // 查看摄像
    videoChange() {
      this.videoOpen = true;
      //模拟摄像头预览
    },
    // 关闭摄像头弹窗
    videoClose() {
      this.videoOpen = false;
      this.closeWindow();
    },
    getList() {
      this.loading = true;
      listAerationResult(this.queryParams).then(response => {
        this.areationresultList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    //表单重置
    reset() {
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      debugger
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除选中"'+ids+'"的数据项？').then(function() {
        return delAerationResult(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
};
</script>
